﻿

using System.Data;

/// <summary>
/// Summary description for DirectServiceProblem
/// </summary>
public class DirectServiceProblem
{

     private ConnectionBase sgbdr;
    public DirectServiceProblem()
    {
      sgbdr= new ConnectionBase();
    }
    public DataTable GetProblemDisplayed(string whereclause, string orderclause)
    {

        //string sql = "select CompanyId,CompanyName,Phone,Fax,Email,Vat,CONVERT(decimal(8, 2), Vat) from COMPANYCONCERNING inner join TCategories  on COMPANYCONCERNING.CategoryId=TCategories.CategoryId";
        string sql = "SELECT PROBLEM.PROBLEMID, "
                         + "PROBLEM.PROBLEM, TYPEEQUIPMENT.TYPEEQUIPMENT, "
                         + "GROUPEPROBLEM.GROUPEPROBLEMID,GROUPEPROBLEM.GROUPEPROBLEM FROM PROBLEM "
                         + "INNER JOIN GROUPEPROBLEM ON "
                         + "PROBLEM.GROUPEPROBLEMID = GROUPEPROBLEM.GROUPEPROBLEMID "
                         + "INNER JOIN TYPEEQUIPMENT ON "
                         + "TYPEEQUIPMENT.TYPEEQUIPEMENTID = GROUPEPROBLEM.TYPEEQUIPEMENTID";
        sql += whereclause + " " + "Order by PROBLEM.Problem";
        return sgbdr.consultSQL(sql).Tables[0];

    }
    public DataTable InitEdit(int problemId)
    {

        string sql = "SELECT PROBLEMID,PROBLEM,GROUPEPROBLEM.TYPEEQUIPEMENTID,TYPEEQUIPMENT,GROUPEPROBLEM.GROUPEPROBLEM,GROUPEPROBLEM.GROUPEPROBLEMID,PROBLEM FROM PROBLEM INNER JOIN GROUPEPROBLEM ON GROUPEPROBLEM.GROUPEPROBLEMID=PROBLEM.GROUPEPROBLEMID INNER JOIN TYPEEQUIPMENT ON TYPEEQUIPMENT.TYPEEQUIPEMENTID=GROUPEPROBLEM.TYPEEQUIPEMENTID WHERE PROBLEMID=" + problemId;
        return sgbdr.consultSQL(sql).Tables[0];
    }
    public void UpdateProblem(int problemId,string newProblem)
    {
        string sql = "update PROBLEM set problem=" + "'" + newProblem + "'" + "where problemId=" + problemId;
        sgbdr.executeSQL(sql);

    }
    public void DeteteProblem(int problemId)
    {
        string sql = "delete From PROBLEM where ProblemId =" + problemId;
        sgbdr.executeSQL(sql);
    }
}
